package com.whw.fy.controller;

import com.whw.fy.entity.Emergency;
import com.whw.fy.entity.Message;
import com.whw.fy.service.EmergencyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Api(tags = "待办事件模块")
@RestController
@RequestMapping("/api/emergency")
public class EmergencyController {
    @Resource
    private EmergencyService emergencyService;

    @ApiOperation(value = "添加待办事件")
    @PostMapping("/one")
    public Message insert(Emergency emergency) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (emergency.getEmergencyTimeToString()!=null)
        emergency.setEmergencyTime(simpleDateFormat.parse(emergency.getEmergencyTimeToString()));
        return emergencyService.insertSelective(emergency);
    }




    @ApiOperation(value = "根据事件id查看待办事件")
    @GetMapping("/id")
    public Message selectById(Integer emergencyId) {
       return emergencyService.selectByPrimaryKey(emergencyId);
    }

    @ApiOperation(value = "根据事件id修改待办事件")
    @PutMapping("/")
    public Message update(Emergency emergency) throws ParseException {
        return emergencyService.updateByPrimaryKeySelective(emergency);
    }

    @ApiOperation(value = "根据事件id删除待办事件")
    @DeleteMapping("/")
    public Message delete(Integer emergencyId) {
        return emergencyService.deleteByPrimaryKey(emergencyId);
    }

    @ApiOperation(value = "获取所有待办事件")
    @GetMapping("/all")
    public Message selectAll(){
        return emergencyService.selectAll();
    }

    @ApiOperation(value = "根据班级id和上课次数查询待办事件")
    @GetMapping("/selectByClassIdAndSKCS")
    public Message selectByEmergencyClazzIdAndEmergencyClazzSkcd(int clazzId,int clazzSkcd){
        return emergencyService.selectByEmergencyClazzIdAndEmergencyClazzSkcd(clazzId,clazzSkcd);
    }

    @ApiOperation(value = "根据班级id、上课次数和学生id查询待办事件")
    @GetMapping("/selectAll")
    public Message selectAllByEmergencyClazzIdAndEmergencyStudentIdAndEmergencyClazzSkcd(Integer emergencyClazzId,Integer emergencyStudentId,Integer emergencyClazzSkcd){
        return emergencyService.selectAllByEmergencyClazzIdAndEmergencyStudentIdAndEmergencyClazzSkcd(emergencyClazzId,emergencyStudentId,emergencyClazzSkcd);
    }

    @ApiOperation(value = "根据待办事件团体类型查询待办事件")
    @GetMapping("/emergencyMold")
    public Message selectByEmergencyMold(Integer emergencyMold) {
        return emergencyService.selectAllByEmergencyMold(emergencyMold);
    }
}
